/*******************************************************************************************************/
/*******************************************************************************************************/
/* */                                                                           //
/* */   #ifndef CALIBRATE_LOAD_SENSING                                                   //
/* */   #define CALIBRATE_LOAD_SENSING                                                   //

/* */   #include "fet.h"
/* */                                                                           //
/* */   void calibrate_load_sense(unsigned int  ui_Calibrated_Scissor_Angle_Array[]               // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_Calibrated_Cylinder_Pressure_Array[]           // Output: The cooresponding array of stored cylinder pressures
/* */                        , unsigned int  ui_NoLoad_Angle_Sensor_Array[]                 // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_NoLoad_Pressure_Sensor_Array[]              // Output: The cooresponding array of stored cylinder pressures
/* */                        , unsigned int  ui_Up_Calibrated_Scissor_Angle_Array[]            // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_Up_Calibrated_Cylinder_Pressure_Array[]           // Output: The cooresponding array of stored cylinder pressures
/* */                        , unsigned int  ui_Up_NoLoad_Angle_Sensor_Array[]                 // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_Up_NoLoad_Pressure_Sensor_Array[]              // Output: The cooresponding array of stored cylinder pressures
/* */                        , unsigned int  ui_Dn_Calibrated_Scissor_Angle_Array[]            // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_Dn_Calibrated_Cylinder_Pressure_Array[]           // Output: The cooresponding array of stored cylinder pressures
/* */                        , unsigned int  ui_Dn_NoLoad_Angle_Sensor_Array[]                 // Output: The array of stored scissor angles
/* */                        , unsigned int  ui_Dn_NoLoad_Pressure_Sensor_Array[]              // Output: The cooresponding array of stored cylinder pressures
//                         ,unsigned int  ui_Load_Sensing_Time_Sensor_Array[]
//                         ,unsigned int  ui_NoLoad_Time_Sensor_Array[]
/* */                        , unsigned char uc_Load_Sensing_Array_Size                  // Input: The number of elements in each stored array
/* */                        , unsigned char *uc_Calibration_Status                      // Output: The calibration status and errors
/* *///                      ,unsigned int  *ui_Max_Cylinder_Angle
                                 );                   // Output: The calibration status and errors
/* */                                                                           //
/* */   unsigned char check_for_sensor_errors(unsigned int ui_Angle_Sensor_Value                     //
      /*   */                               , unsigned int ui_Pressure_Sensor_Value);          //
/* */                                                                           //
/* */  unsigned char check_for_sensor_errors2(unsigned int ui_Pressure_Sensor_Value
      , unsigned int ui_Pressure_Sensor_Value2);              //  Aaron@20170322

/* *///GTF  void update_display (unsigned int ui_Display_Information);                             //
/* */   void delay_mSec(unsigned int ui_Delay);                                          //
/* */   void lower_the_platform(unsigned int  ui_Calibrated_Scissor_Angle_Array[]                 //
                                /* */                     , unsigned char uc_Errors);                                 //
/* */   void blow_horn(void);                                                         //
/* */   void blow_horn_fast(void);
/* */   void display_byte(unsigned char uc_Byte_to_Display);                                                        //
/* */   unsigned char calibration_procedure_start_sequence(void);                              //
/* */   unsigned char check_calibration_switches(void);                                     //
/* */                                                                           //

/* */   extern void DISPLAY_ECU(void);                                                //
/* */   extern Fet_t Fets;                                                            //
/* */   extern unsigned int read_angle_sensor(void);                                     //
/* */   extern unsigned int read_cylinder_pressure(void);                                   //
/* */   extern struct TIMER TIMER_Data;                                                  //
/* */                                                                           //
/* */   #define ACTIVATED_SWITCH_TIME_OUT 4                                              //
/* */   #define BACKGROUND_LOOP_TIME 10                                                  // mSec
/* */   #define CHASSIS_DOWN_SWITCH_IS_ACTIVATED u8GetStatus12A()//IO.PDR5.BIT.B3                                //
/* */   #define CHASSIS_UP_SWITCH_IS_ACTIVATED u8GetStatus12B()//IO.PDRB.BIT.B0                               //
/* */   #define DEACTIVATED_SWITCH_TIME_OUT 8                                            //
/* */   #define DOWN_SWITCH 1                                                         //
/* */   #define FEED_THE_WATCHDOG  {R_WDT_Restart();}                                       //
 /* */   #define MAXIMUM_ALLOWABLE_ANGLE_SENSOR_VOLTAGE     920   //4.95 Volts
 /* */   #define MAXIMUM_ALLOWABLE_PRESSURE_SENSOR_VOLTAGE  920   //4.95 Volts
 /* */   #define MINIMUM_ALLOWABLE_ANGLE_SENSOR_VOLTAGE     28 //0.15 Volts
 /* */   #define MINIMUM_ALLOWABLE_PRESSURE_SENSOR_VOLTAGE  28 //0.15 Volts
 /* */   #define MAXIMUM_SUM_ALLOWABLE_PRESSURE_SENSOR_VOLTAGE 1170 //28mA, 24mA=1003
 /* */   #define MINIMUM_SUM_ALLOWABLE_PRESSURE_SENSOR_VOLTAGE   830//20mA, 24mA=1003
/* */   #define RAISE_PLATFORM_TIME 4500  //2000                                               // milliSeconds
/* */   #define RAISE_PLATFORM_TIME_AMWP 4500  //2000                                                // milliSeconds
 /* */   #define RAISE_PLATFORM_TIME_ELEC 2000  //2000                                                // milliSeconds
/* */   //#define SHIFT_DATA_INTO_FET {P7_bit.no5 = 0;P7_bit.no5 = 1;}//{IO.PDR8.BIT.B5 = 0; IO.PDR8.BIT.B5 = 1;}                    //
/* */   #define STABILIZATION_DELAY 6000                                                 // milliSeconds of delay.
/* */   #define UP_SWITCH 2                                                           //
/* */   #define PRES_DIFF_THRESHOLD 100                                                  //
#define CAL_DOWN_LOOPS 600
         #define UP_LIMIT_OFFSET  0
         #define DOWN_LIMIT_OFFSET  10
/* */                                                                           //
/*******************************************************************************************************/
/*******************************************************************************************************/
//   //                                                                         //
//   //          Platform Control Bit Definitions                                     //
//   //                                                                         //
//   //          Bit      Function                                                 //
//   //          ---      -----------------------------------------                         //
//   //          15    Not Used                                                 //
//   //          14    Sel3  (Selection Line 3          )                          //
//   //          13    Sel2  (Selection Line 2          )                          //
//   //          12    Sel1  (Selection Line 1          )                          //
//   //                                                                         //
//   //          11    Alarm                                                    //
//   //          10    DRV11 (Driver 11 - Spare 1 - Not Used )                           //
//   //           9    DRV10 (Driver 10 - Hour Meter       )                          //
//   //           8    DRV9  (Driver  9 - Horn          )                          //
//   //                                                                         //
//   //           7    DRV8  (Driver 8 - Motor Control     )                          //
//   //           6    DRV7  (Driver 7 - Beacon            )                          //
//   //           5    DRV6  (Driver 6 - Steer Left        )                          //
//   //           4    DRV5  (Driver 5 - Steer Right       )                          //
//   //                                                                         //
//   //           3    DRV4  (Driver 4 - Platform Down     )                          //
//   //           2    DRV3  (Driver 3 - Platform Raise    )                          //
//   //           1    DRV2  (Driver 2 - Forward/Reverse2  )                          //
//   //           0    DRV1  (Driver 1 - Forward/Reverse1  )                          //
//   //                                                                         //
//   //                                                                         //
/* */   #define END_PLATFORM_CALIBRATION 0x1000                                             //
/* */   #define LOWER_PLATFORM 0x1008                                                 //
/* */   #define LOWER_PLATFORM_W_HORN 0x1908                                             //
/* */   #define RAISE_PLATFORM 0x1084    // FET_SEL1 &            FET_MCE & FET_UP             //
/* */   #define RAISE_PLATFORM2 0x1284      // FET_SEL1 & FET_MCE2 & FET_MCE & FET_UP             //
/* */   #define STOP_PLATFORM_MOVEMENT 0x1000                                            //
/* */   #define TEST_HORN 0x1900                                                      //
/* */   #define TEST_OUTPUT 0x1FFF                                                    //
/* */   #define TEST_STAGING 0x1000                                                      //
/* */   #define TEST_STEER_LEFT 0x1020                                                   //
/* */   #define TEST_STEER_RIGHT 0x1010                                                  //
/* */   #define TEST_FORWARD 0x1002                                                      //

//   //                                                                         //
//   //                                                                         //
/*******************************************************************************************************/
/* */                                                                           //
/* */                                                                           //
/* */   #endif                                                                     //
/* */                                                                           //
/**********END**********END**********END**********END**********END**********END**********END************/
